//
//  ZGLDetaiHeaderView.m
//  ZeegingLottery
//
//  Created by 李曌 on 2018/10/23.
//  Copyright © 2018 蒂埃里. All rights reserved.
//

#import "ZGLDetaiHeaderView.h"

@interface ZGLDetaiHeaderView ()
{
    CGFloat silderX;
}

@property (weak, nonatomic) IBOutlet UIView *silder;

@property (weak, nonatomic) IBOutlet UIView *colorTips;
@property (weak, nonatomic) IBOutlet UIImageView *weatherImage;
@property (weak, nonatomic) IBOutlet UIImageView *homeIcon;
@property (weak, nonatomic) IBOutlet UIImageView *awayIcon;
@property (weak, nonatomic) IBOutlet UILabel *homeTeam;
@property (weak, nonatomic) IBOutlet UILabel *awayTeam;

@property (weak, nonatomic) IBOutlet UILabel *matchDateLabel;

@property (weak, nonatomic) IBOutlet UIButton *messageBtn;
@property (weak, nonatomic) IBOutlet UIButton *analysisBtn;

@property (weak, nonatomic) IBOutlet UIView *menuBgView;

@property (weak, nonatomic) IBOutlet UILabel *GameTime;


@end

@implementation ZGLDetaiHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    self = [[[NSBundle mainBundle] loadNibNamed:@"ZGLDetaiHeaderView" owner:nil options:nil] lastObject];
    if (self) {
        self.frame = frame;
        [self.messageBtn addTarget:self action:@selector(menuBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.analysisBtn addTarget:self action:@selector(menuBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        self.homeTeam.font = kFONT_SIZE(13);
        self.awayTeam.font = kFONT_SIZE(13);
        
        
    }
    return self;
}

- (void)setModel:(ZGLMatchModel *)model
{
    _model = model;
    NSString *imageHeader = @"http://betcat.zeeging.com";
    
    self.GameTime.text = model.statustips;
    self.colorTips.backgroundColor = [PublicMethod colorFromHex:model.color];
    
    //天气
    NSURL *WeatherUrl = [NSURL URLWithString:model.weathericon];
    [self.weatherImage sd_setImageWithURL:WeatherUrl placeholderImage:[UIImage imageNamed:@"cloudy.png"]];
    
    //联赛&时间
    NSString *matchDateSrt = [NSString stringWithFormat:@"%@ %@",model.leaguenameabbr,model.matchkeycn];
    self.matchDateLabel.text = matchDateSrt;
    
    //主队
    self.homeTeam.text = model.homename;
    NSString *homeImageUrl = [NSString stringWithFormat:@"%@%@",imageHeader,model.homelogo];
    [self.homeIcon sd_setImageWithURL:[NSURL URLWithString:homeImageUrl] placeholderImage:[UIImage imageNamed:@"teamLogo_default"]];
    
    //客队
    self.awayTeam.text = model.awayname;
    NSString *awayImageUrl = [NSString stringWithFormat:@"%@%@",imageHeader,model.awaylogo];
    [self.awayIcon sd_setImageWithURL:[NSURL URLWithString:awayImageUrl] placeholderImage:[UIImage imageNamed:@"teamLogo_default"]];
    
}

- (void)menuBtnClick:(UIButton *)sender
{
    DLog(@"%@",sender.titleLabel.text);
    [self changeSilderFrame:sender];
    
    if (self.buttonTag) {
        self.buttonTag(sender.tag);
    }
    
}



//- (IBAction)messageBtnClick:(id)sender {
//
//    DLog(@"情报");
//    UIButton *button = (UIButton *)sender;
//    CGFloat tag = button.tag;
//    if (self.buttonTag) {
//        self.buttonTag(tag);
//    }
//
//    [self changeSilderFrame:button];
//
//
//}
//
//- (IBAction)analysisBtnClick:(id)sender {
//
//    DLog(@"分析");
//    UIButton *button = (UIButton *)sender;
//    CGFloat tag = button.tag;
//    if (self.buttonTag) {
//        self.buttonTag(tag);
//    }
//    [self changeSilderFrame:button];
//
//}

- (void)changeMenuSelectedWith:(NSInteger )index
{
    for (UIView *view in self.menuBgView.subviews) {
        if ([view isKindOfClass:[UIButton class]] && view.tag == index) {
            UIButton *button = (UIButton *)view;
//            [self didClickButton:button];
            [self menuBtnClick:button];
            break;
        }
    }
}


- (void)changeSilderFrameWith:(UIButton *)button
{
    [self changeSilderFrame:button];
    
}


//
- (void)changeSilderFrame:(UIButton *)button
{
    CGFloat centX = CGRectGetMidX(button.frame);
    silderX = CGRectGetMidX(self.silder.frame);
    
    if (centX != silderX) {
        
        [UIView animateWithDuration:0.3 animations:^{
            
            [self.silder setCenterX:centX];
            silderX = centX;
        }];
    }
}

@end
